#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int i = 0; 
	int j = 0;
	int arr1[3][3] = { 0 };
	int arr2[3][3] = { 0 };
	int n = 0;
	int m = 0;
	double tem = 0;
	double count = 0;
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &arr1[i][j]);
		}
		
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &arr2[i][j]);
		}
		
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			if (arr1[i][j] == arr2[i][j])
				count++;
		}
	}
	count = count / 1.0;
	tem = count /(n*m)*100 ;
	printf("%.2lf", tem);
	return 0;
}